package com.petalsgroup.petals.dao.comInform.impl;

import com.petalsgroup.petals.dao.comInform.ComInformDao;
import com.petalsgroup.petals.pojo.ComInformDO;
import com.petalsgroup.petals.pojo.DisInformDO;
import com.petalsgroup.petals.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class ComInformDaoImpl implements ComInformDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource());

    /**
     * 根据ID查询某个用户所有影评的总举报数
     * @param uided
     * @return
     * @author wgd
     */
    @Override
    public Long getComInformNunByUided(Integer uided) {
        String sql="select count(*) from com_inform where uided = ?";
        Long comCount = template.queryForObject(sql, long.class, uided);
        return comCount;
    }

    /**
     * 根据ID删除某个用户所有影评举报记录
     * @param uided
     * @author wgd
     */
    @Override
    public void deleteComInformByUided(Integer uided) {
        String sql="delete from com_inform where uided = ?";
        template.update(sql,uided);
    }

    /**
     * 判断用户是不是已经举报过这条影评
     * @param uid
     * @param com_id
     * @return
     * @author wgd
     */
    @Override
    public Boolean comInformAgain(Integer com_id,Integer uid ) {
        String sql="select * from petal.com_inform where uid = ? and com_id = ? ";
        List<ComInformDO> list = template.query(sql, new BeanPropertyRowMapper<>(ComInformDO.class), uid, com_id);

        System.out.println(list.size()>0);
        return list.size()>0 ;
    }

    /**
     * 将举报记录插入表中
     * @param com_id
     * @param uid
     * @param uided
     * @param iid
     * @author wgd
     */
    @Override
    public void addComInform(String com_id, String uid, String iid, String uided) {
        String sql = "insert into com_inform values(?,?,null,?,?)";
        template.update(sql,com_id,uid,iid,uided);
    }


}
